using System;
using System.Collections.Generic;
using System.Reflection;

using Elev.Core.DAL;
using Elev.Core.Data;

namespace Elev.Core
{
    public static class SqliteTablesCreator
    {
        static private List<Type> getSqliteTableTypes()
        {
            List<Type> types = new List<Type>();
            foreach (Type type in Assembly.GetExecutingAssembly().GetTypes())
                if (type.BaseType == typeof(SqliteTable) && type.IsClass && !type.IsAbstract)
                    types.Add(type);

            return types;
        }
        
        static public void CreateTables()
        {
            foreach (Type type in getSqliteTableTypes())
            {
                SqliteTable table = (SqliteTable)Activator.CreateInstance(type);
                table.Create();
            }
        }

        /// <summary>
        /// Method used to clean up data. Intended to be used in unit testing ...
        /// </summary>
        static public void TruncateTables()
        {
            foreach (Type type in getSqliteTableTypes())
            {
                SqliteTable table = (SqliteTable)Activator.CreateInstance(type);
                table.Truncate();
            }
        }
    }
}
